package com.example.smallmall.dto;

import com.example.smallmall.entity.SpManager;
import com.example.smallmall.entity.SpPermission;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * SpringSecurity需要的用户详情
 * Created by WSGL on 2020-08-16.
 */
public class AdminUserDetails implements UserDetails {

    private final SpManager spManager;

    public AdminUserDetails(SpManager spManager) {
        this.spManager = spManager;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return spManager.getMgPwd();
    }

    @Override
    public String getUsername() {
        return spManager.getMgName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return spManager.getMgState().equals(true);
    }
}
